Define different visual states for a control (Windows Phone)

You can create interactivity in your application by defining a different visual appearance for each visual state that your UserControl control, Page control, or control template can be in, and then add code to switch between those states based on user interaction. You can modify the transition between two state combinations, even creating animations that will run when a state is first entered.

State groups

A state group contains any visual states that are part of the same logical category, and that cannot be displayed at the same time. Only one state in a state group can be displayed at a time, but a state from one group can be displayed at the same time as a state in another state group.

For example, if you were working with a UserControl control that represented a playing card, you might have a state group named "SideDisplayed" that included states that display the card face-up (FaceUp) and face-down (FaceDown). You might also have a state group named "MouseInteraction" that included states that change the appearance of the card when the pointer is over the card (PointerOver), and when the card is clicked (Click). A card can be face-up and have the pointer move across it at the same time, so those states are in different state groups. However, the card cannot be face-up and face-down at the same time, so those two states can be in the same state group.

State groups and states of a playing card

For more information, see Define different visual states and transition times for a user control (Windows Phone).

States

When you select a state, state recording is turned on, and any changes that you make will be recorded for that state. To turn off state recording, click the recording button , or select Base in the States panel. If you want to change the appearance of a state in one state group while also viewing the control in the state of another state group, you can pin a preview of the second state while in recording mode for the first state.

For more information, see Define different visual states and transition times for a user control (Windows Phone).

To change between states, you can use the GoToState method, or you can write code in an event handler.

Transitions

You can extend the amount of time that it takes to transition between states when a state change occurs. You can set the transition duration for an entire state group, or for the transitions that occur between specific combinations of states.

For more information, see Modify the transition time between state changes (Windows Phone) and Define different visual states and transition times for a user control (Windows Phone).

If you want to create a smooth transition between states that modify layout properties that are discrete values (such as column or row numbers) or set automatically (such as width and height), you can use fluid layout.

See Also

Tasks

Create a new user control (Windows Phone)

Create a reusable template to style a system control (Windows Phone)

Modify the transition time between state changes (Windows Phone)

Modify the appearance of a system control in different states (Windows Phone)

Define different visual states and transition times for a user control (Windows Phone)